package hot100;

import java.util.HashMap;
import java.util.Map;

public class majorityElement {
    public int majorityElement(int[] nums) {
        //返回结果
        int ret = 0;

        int n = nums.length;
        Map<Integer,Integer> hash = new HashMap<>();
        for(int x : nums) {
            hash.put(x,(hash.getOrDefault(x,0)+1));
            int tem = hash.get(x);
            if(tem > n/2) {
                ret = x;
                break;
            }
        }
        return ret;
    }
}
